
import { Navigate,useLocation } from "react-router-dom"
import { matchRoute } from "../views/utils/utils";
import { router_item } from "../router";
export default function AuthRouter(props:{children:JSX.Element}) {
    
    // 判断token是否存在 返回一个重定向的路由
    const token=localStorage.getItem('token')
    const {pathname}=useLocation()
    const router=matchRoute(pathname,router_item)
   if (router.meta?.unWantedAuth ){return props.children}
  return  token ? props.children : <Navigate to="/login" />
}
